Central Article

The Building Blocks of a Central Application


Table of Contents

  1. Introduction
  2. The Application
  3. The Pod
  4. The Agent and LCService
  5. Notices
  6. Sending a Blast
  7. Receiving a Blast
  8. The product.xml File

The Agent

The most common use for an agent is as the server in an LCService. An LCService, or Local Connection Service, always establishes a connection between a server and a client. Do not confuse this with an HTTP server, however; in this case, "server" merely means that the agent serves or processes data, which the client consumes. In this case, the client is the application.

When you use LCService, there are a few lines of code that the client and server share. It makes sense to create a separate file, which you then #include in both. In my example, Interface.as is the shared file; it defines the way the client and server will interface:

IAgent = new Object();
IAgent.name = "IAgent";
IAgent.interfaces = new Object();
IAgent.interfaces.Client = [];
IAgent.interfaces.Server = ["doRespond"];

The interface specifies two sets of functions, which the server can call on the client and vice versa. In this specific example, the client doesn't make any methods available to the server, but the server defines a doRespond method. The client can invoke this method.

Note that the interface doesn't actually set up the LCService between the client and server; it merely provides an interface. The syntax for setting up the client and server is as follows.

// Creating the client, usually the app itself
serviceName = Central.LCService.createClient(agentName, clientName, this, false);

// Creating the server, usually the agent
serviceName = Central.LCService.createServer(agentName, this, false);

The line containing createClient() goes in the application code, or in whichever other actor you want to be the client. The line containing createServer() goes in the server code, in this case, the init.as file in the agent folder.

The variables serviceName and agentName must be the same on the client side and the server side. Note that if you want this to be a synchronous service, the last parameter should be true on both sides.

You can start and stop the agent can from the application with Shell.startAgent() and Shell.stopAgent().

For more information on LCService, please refer to Ethan Malasky's article, Understanding and Using the LCService Library.